<?php

namespace app\api\controller;

use app\api\service\UserToken;
use think\Controller;
use think\facade\Request;

class Common extends Controller
{
    /**
     * 重写response方法
     * @param array $result
     * @param int $code
     * @param int $errorCode
     * @param string $msg
     * @return \think\response\Json
     */
    protected function response($result = [], $code = 200, $errorCode = 0, $msg = '')
    {
        $return = [
            'errorCode' => $errorCode,
            'msg' => '',
            'url' => Request::instance()->url(),
            'data' => $result
        ];
        return json($return, $code);
    }

    /**
     * 管理员和普通用户权限
     * @return bool
     * @throws \app\lib\exception\ThrowError
     * @throws \think\Exception
     */
    protected function checkPrimaryScope()
    {
        return UserToken::checkPrimaryScope();
    }

    /**
     * 普通用户权限
     * @return bool
     * @throws \app\lib\exception\ThrowError
     * @throws \think\Exception
     */
    protected function checkExclusiveScope()
    {
        return UserToken::checkExclusiveScope();
    }
}
